<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Attributes of Primitive Components</title>
<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Spirit X3 3.0.9">
<link rel="up" href="../abstracts.html" title="Abstracts">
<link rel="prev" href="parsing_expression_grammar.html" title="Parsing Expression Grammar">
<link rel="next" href="compound_attributes.html" title="Attributes of Compound Components">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="parsing_expression_grammar.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="compound_attributes.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="spirit_x3.abstracts.primitive_attributes"></a><a class="link" href="primitive_attributes.html" title="Attributes of Primitive Components">Attributes
      of Primitive Components</a>
</h3></div></div></div>
<p>
        Parsers in <a href="http://boost-spirit.com" target="_top">Spirit</a> are fully
        attributed. <span class="emphasis"><em>Spirit.X3</em></span> parsers always <span class="emphasis"><em>expose</em></span>
        an attribute specific to their type. This is called <span class="emphasis"><em>synthesized
        attribute</em></span> as it is returned from a successful match representing
        the matched input sequence. For instance, numeric parsers, such as <code class="computeroutput"><span class="identifier">int_</span></code> or <code class="computeroutput"><span class="identifier">double_</span></code>,
        return the <code class="computeroutput"><span class="keyword">int</span></code> or <code class="computeroutput"><span class="keyword">double</span></code> value converted from the matched input
        sequence. Other primitive parser components have other intuitive attribute
        types, such as for instance <code class="computeroutput"><span class="identifier">int_</span></code>
        which has <code class="computeroutput"><span class="keyword">int</span></code>, or <code class="computeroutput"><span class="identifier">ascii</span><span class="special">::</span><span class="identifier">char_</span></code> which has <code class="computeroutput"><span class="keyword">char</span></code>.
        Primitive parsers apply the normal C++ convertibility rules: you can use
        any C++ type to receive the parsed value as long as the attribute type of
        the parser is convertible to the type provided. The following example shows
        how a synthesized parser attribute (the <code class="computeroutput"><span class="keyword">int</span></code>
        value) is extracted by calling the API function <code class="computeroutput"><span class="identifier">x3</span><span class="special">::</span><span class="identifier">parse</span></code>:
      </p>
<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">value</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">str</span><span class="special">(</span><span class="string">"123"</span><span class="special">);</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">::</span><span class="identifier">iterator</span> <span class="identifier">strbegin</span> <span class="special">=</span> <span class="identifier">str</span><span class="special">.</span><span class="identifier">begin</span><span class="special">();</span>
<span class="identifier">x3</span><span class="special">::</span><span class="identifier">parse</span><span class="special">(</span><span class="identifier">strbegin</span><span class="special">,</span> <span class="identifier">str</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">int_</span><span class="special">,</span> <span class="identifier">value</span><span class="special">);</span>   <span class="comment">// value == 123</span>
</pre>
<p>
        For a full list of available parser primitives and their attribute types
        please see the sections X3 Parsers.
      </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2018 Joel de Guzman,
      Hartmut Kaiser<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="parsing_expression_grammar.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstracts.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="compound_attributes.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
